package com.work.vo.main;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.work.constant.DictBizConstant;
import com.work.utils.BigDecimalSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.DictBizCache;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 综合统计退关台账详情
 *
 * @author ：dujianyu
 * @since ：Created in 2024/7/9 8:37
 */
@Data
public class RetreatSetStatDetailVO {

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "ID",notes = "")
    private Long id ;

    @ApiModelProperty(name = "时间",notes = "")
    private LocalDate tallyDate;

    @ApiModelProperty(name = "时间段",notes = "")
    private String timeSpace;

    @ApiModelProperty(name = "时间段",notes = "")
    private String timeSpaceName;

    public String getTimeSpaceName() {
        if (Func.isNull(timeSpace)) {
            return "";
        }
        return DictBizCache.getValue(DictBizConstant.TIME_SPACE, timeSpace);
    }

    @ApiModelProperty(value = "时间信息")
    private String timeInfo;

    public String getTimeInfo() {
        if (Func.isNull(timeSpace) || Func.isNull(tallyDate)) {
            return "";
        }
        return tallyDate + "/" + DictBizCache.getValue(DictBizConstant.TIME_SPACE, timeSpace);
    }

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "退关垛ID",notes = "")
    private Long retreatStorageId ;

    @ApiModelProperty(value = "货场")
    private String positionName;

    @ApiModelProperty(value = "货位")
    private String spot;

    @ApiModelProperty(value = "货位")
    private String positionInfo;

    public String getPositionInfo() {
        if (Func.isNull(positionName) || Func.isNull(spot)) {
            return "";
        }
        return positionName + "/" + spot;
    }

    @ApiModelProperty(value = "退关类型")
    private String retreatType;

    @ApiModelProperty(value = "退关类型")
    private String retreatTypeName;

    public String getRetreatTypeName() {
        if (Func.isNull(retreatType)) {
            return "";
        }
        return DictBizCache.getValue(DictBizConstant.RETREAT_TYPE, retreatType);
    }

    @ApiModelProperty(name = "退关设置件数",notes = "")
    private Integer retreatPiece ;

    @JsonSerialize(using = BigDecimalSerializer.class)
    @ApiModelProperty(name = "退关设置吨数",notes = "")
    private BigDecimal retreatTon ;

    @ApiModelProperty(value = "退关设置件吨")
    private String retreatPieceTonInfo;

    public String getRetreatPieceTonInfo() {
        if (Func.isNull(retreatPiece) || Func.isNull(retreatTon)) {
            return "";
        }
        return retreatPiece + "/" + retreatTon.stripTrailingZeros().toPlainString();
    }

    @ApiModelProperty(name = "提货件数",notes = "")
    private Integer outPiece;

    @JsonSerialize(using = BigDecimalSerializer.class)
    @ApiModelProperty(name = "提货吨数",notes = "")
    private BigDecimal outTon;

    @ApiModelProperty(value = "提货件吨")
    private String outPieceTonInfo;

    public String getOutPieceTonInfo() {
        if (Func.isNull(outPiece) || Func.isNull(outTon)) {
            return "";
        }
        return outPiece + "/" + outTon.stripTrailingZeros().toPlainString();
    }

    @ApiModelProperty(name = "结余件数",notes = "")
    private Integer leftPiece ;

    public Integer getLeftPiece() {
        if (Func.isNull(retreatPiece) || Func.isNull(outPiece)) {
            return null;
        }
        return retreatPiece - outPiece;
    }

    @JsonSerialize(using = BigDecimalSerializer.class)
    @ApiModelProperty(name = "结余吨数",notes = "")
    private BigDecimal leftTon ;

    public BigDecimal getLeftTon() {
        if (Func.isNull(retreatTon) || Func.isNull(outTon)) {
            return null;
        }
        return retreatTon.subtract(outTon);
    }

    @ApiModelProperty(value = "结余件吨")
    private String leftPieceTonInfo;

    public String getLeftPieceTonInfo() {
        if (Func.isNull(outPiece) || Func.isNull(outTon)) {
            return "";
        }
        if (Func.isNull(retreatPiece) || Func.isNull(retreatTon)) {
            return "";
        }
        return (retreatPiece - outPiece) + "/" + retreatTon.subtract(outTon).stripTrailingZeros().toPlainString();
    }

    @ApiModelProperty(value = "姓名")
    private String createUserName;
}
